<?php
namespace App\Lib;

use App\Models\IndexBillNo;
use App\Models\IndexOrderno;
use Illuminate\Support\Facades\DB;

class SystemNumber
{
    protected static function suffix()
    {
        return date('YmdHis') . substr(time(), -3) . random_int(0,9);
    }

    public static function getRechargeOrderNumber($mch_code)
    {
        $index = IndexOrderno::create(['mch_code' => $mch_code]);
        $id = $index->id < 10000 ? str_pad($index->id, 5, 0, STR_PAD_LEFT) : $index->id;
        return date('YmdHis') . $id . substr(time(), -3);
    }

    public static function getWithdrawOrderNumber()
    {
        return 'WD' . self::suffix();
    }

    public static function getToPayPrefixNumber()
    {
        return 'TP' . self::suffix();
    }

    public static function getToPayOrderNumber($prefix, $number)
    {
        return $prefix . str_pad($number, 2, '0', STR_PAD_LEFT);
    }

    public static function getBatchNoNumber()
    {
        return date('YmdHis') . substr(time(), -3);
    }

    public static function getBillRecordNumber($code = BillTypeMap::RECHARGE)
    {
        $index = IndexBillNo::create();
        $id = $index->id < 10000 ? str_pad($index->id, 5, 0, STR_PAD_LEFT) : $index->id;
        return date('YmdHis') . $code . $id . substr(time(), -3);


    }

}
